﻿Imports System.Data.SqlClient

Public Class clsIPScanner
    Private mstrIP As String
    Private mstrUbicacion As String
    Public Property IP() As String
        Get
            Return mstrIP
        End Get
        Set(ByVal value As String)
            mstrIP = value
        End Set
    End Property
    Public Property Ubicacion() As String
        Get
            Return mstrUbicacion
        End Get
        Set(ByVal value As String)
            mstrUbicacion = value
        End Set
    End Property

    Public Sub New()
        mstrIP = ""
        mstrUbicacion = ""
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into IPScanner (" & _
                            "IP," & _
                            "Ubicacion)" & _
                            "VALUES (" & _
                            "@IP," & _
                            "@Ubicacion)"


        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)
        Command.Parameters.AddWithValue("IP", mstrIP)
        Command.Parameters.AddWithValue("Ubicacion", mstrUbicacion)

        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar la Liquidacion ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
    Public Sub Actualizar()
        Dim strSqlQry As String
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        strSqlQry = "Update IPScanner Set " & _
                    "IP=@IP " & _
                     "Where Ubicacion=@Ubicacion"


        Dim Command As New SqlCommand(strSqlQry, cnConn)
         Command.Parameters.AddWithValue("IP", mstrIP)
        Command.Parameters.AddWithValue("Ubicacion", mstrUbicacion)

        cnConn.Open()

        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible actualizar el liquidación ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
End Class
